<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*,org.atf.utils.ATFUtils,org.atf.model.entity.User" %>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>ATF Login Page</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">
    
	    <!-- Core Scripts - Include with every page -->
	  <script src="js/jquery-1.10.2.js"></script>
	  <script src="js/bootstrap.js"></script>

    <!-- Custom styles for this template -->
    <link href="css/site.css" rel="stylesheet">                                               
	<script type='text/javascript' src='dwr/engine.js'></script>
	<script type='text/javascript' src='dwr/interface/profileController.js'></script>
	<script type='text/javascript' src='dwr/interface/preferenceController.js'></script>
	<script src="js/alert.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <%
    
    	String username = request.getParameter("username");
        String password = request.getParameter("password");
	    
	
    	
	
     %>
     
     <script>
     	function addUser(uName, pwd, adm, grps){
     		var userData={userId:"", username:uName, password:pwd, admin:adm, groups:grps}
     		profileController.addNewUser(userData,{
			async: false,
			callback:function(data){
				$("#container-message").atf_success("Add "+data);
			}
			});
     	}
     	function addDefaultPreferences(){
			preferenceController.addOrUpdateDefaultsPreference({
				callback: function(data){
					$("#container-message").atf_success("OK "+data);
				}
				
			});
			
		}
		function disableLDAP(){
			preferenceController.disableLDAP({
				callback: function(data){
					$("#container-message").atf_success("OK "+data);
				}
				
			});
			
		}
		function disableTAM(){
			preferenceController.disableTAM({
				callback: function(data){
					$("#container-message").atf_success("OK "+data);
				}
				
			});
			
		}
     </script>
  </head>

  <body>
  		
	<%
		if (username != null && password != null) {
			if( username.equalsIgnoreCase("admin") && password.equalsIgnoreCase("admin4Not3") ){
				session.setAttribute("ATFUser", "admin");
			
	%>	
			<div class="row">
				<div class="col-lg-2">
					<div class="list-group">
					  <a class="list-group-item active">
					  	 Admin Utils
					  </a>
					  <a href="#" onClick="addDefaultPreferences()" class="list-group-item">Add Default Preferences</a>
					  <a href="#" onClick="addUser('TEST','TEST','true','')" class="list-group-item">Add User</a>
					  <a href="#" onClick="disableLDAP()" class="list-group-item">Disable LDAP</a>
					  <a href="#" onClick="disableTAM()" class="list-group-item">Disable TAM</a>
					</div>
				</div>
				<div class="col-lg-10">
					<div id="container-message"></div>
				</div>
			</div>
	<% 
			}
    %>
	<%} else { %>
    
	  <div class="container">
      <form class="form-signin"  action="" method="post" role="form">
        <h2 class="form-signin-heading">Admin Login</h2>
        <input type="text" name="username" class="form-control" placeholder="Username" required autofocus>
        <br>
        <input type="password" name="password" class="form-control" placeholder="Password" required>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>
       </div> <!-- /container -->
	<%} %>
   
  </body>
</html>
